package com.lovo.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.system.dto.CustomerDto;
import com.lovo.system.dto.PageDto;
import com.lovo.system.dto.SupplierDto;
import com.lovo.system.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    ICustomerService customerService;

    @RequestMapping("/info")
    public IPage<CustomerDto> info(@RequestBody PageDto<CustomerDto> pageDto) {
        return customerService.cutByItem(pageDto.getCurPage(), pageDto.getPageSize()
                , pageDto.getData().getCustomerName(), pageDto.getData().getNatureOfBusiness());
    }

    @RequestMapping("/add")
    public String addSupplier(@RequestBody CustomerDto customerDto) {
        return customerService.addCustomer(customerDto);
    }

    @RequestMapping("/delete")
    public String deleteSupplier(int id) {
        return customerService.deleteCustomer(id);
    }

    @RequestMapping("/update")
    public String updateSupplier(@RequestBody CustomerDto customerDto) {
        return customerService.updateCustomer(customerDto);
    }

    @RequestMapping("/one")
    public CustomerDto selectSupplierById(int id) {
        return customerService.queryOneById(id);
    }

}
